import { getMsbdDataListApi,postMsbdDataListApi,deleteMsbdDataListApi,updateMsbdDataListApi} from "~/api/audit"

export const state = () => ({
    list: [],
    classify:[],
    pageSize: 5,
    currentPage: 1,
    total: 400,
})

export const mutations = {
    SET_LIST(state, data) {
        state.list = data.data.data
        state.classify =data.data.classify
        state.total =data.total
    },
    GET_CURRNNTPAGE(state,currentPage){
        state.currentPage=currentPage
    },
    GET_PAGESIZE(state,pageSize){
        state.pageSize=pageSize
    },
}

export const actions = {
    async getMsbdListApi({commit,state},input){
        console.log(123)
      let r =  await getMsbdDataListApi({currentPage:state.currentPage-1,pageSize:state.pageSize,query:input?input.query:""})
      commit("SET_LIST",r)
    },
    async postMsbdListApi({dispatch},form){
        await postMsbdDataListApi(form)
        dispatch("getMsbdListApi")
    },
    async deleteMsbdListApi({dispatch},id){
        await deleteMsbdDataListApi(id)  
        dispatch("getMsbdListApi")
    },
    async updateMsbdListApi({dispatch},form){
        await updateMsbdDataListApi(form)
        dispatch("getMsbdListApi")
    }
}

export const getters = {
    roles: (state) => { return state.users.roles },
    userInfo: (state) => { return state.users.userInfo },
}